export function weeks() { return ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] }

export function parseTime(timeStr) {
  if (!timeStr) return []
  let arr = timeStr.split("&")
  let obj = {}
  const list = weeks();
  arr.forEach(e => {
      let index = e.indexOf(":");
      let list = e.slice(0, index).split("、");
      let times = e.slice(index + 1).split("、");
      list.forEach(e2 => {
        obj[e2] = times;
      })
  });

  return list.map((v, i) => {
    return obj[v] || []
  })
}

// 计算时间是否在区间内  12:00-13:00   12:55 返回true
export function isWorkingInTime(timeStr) {
  if (!timeStr) return false
  const arr = timeStr.split("-");
  const startTime = arr[0];
  const endTime = arr[1];

  const startArr = startTime.split(":");
  const endArr = endTime.split(":");
  
  const date = new Date();

  const currentHour = date.getHours();
  const minute = date.getMinutes();

  const current = currentHour * 60 + minute;
  // console.warn('current', current, startArr, endArr, startArr[0] * 60 + startArr[1], endArr[0] * 60 + endArr[1]);
  if (current >= (Math.floor(startArr[0]) * 60 + Math.floor(startArr[1])) && (current <= Math.floor(endArr[0]) * 60 + Math.floor(endArr[1]))) {
    return true;
  }
  return false;
}